<?php
include_once('../../app/connection.php');

if(isset($_POST['action']))
{
    $action = $_POST['action'];
    
    if($action == 'delete')
    {
        if(isset($_POST['magv']))
        {
            $magv = $_POST['magv'];
            
            $str = "SELECT * FROM giaovien WHERE MAGIAOVIEN='".$magv."'";
            $check = mysql_query($str);
            if(mysql_num_rows($check) == 0)
                echo 'Giảng viên '. $magv .' không tồn tại'; 
            else {
                $sql = "UPDATE giaovien SET TRANGTHAI = 0 WHERE MAGIAOVIEN='".$magv."'";
                $result = mysql_query($sql);       
                echo 'Đã xóa Giảng viên ' . $magv;
            }
        }
        
        if(isset($_POST['array']))
        {
            $array = $_POST['array'];
                        
            for($i=0; $i < count($array); $i++)
            {
                $sql = "UPDATE giaovien SET TRANGTHAI = 0 WHERE MAGIAOVIEN='".$array[$i]."'";
                $result = mysql_query($sql);
            }
            
        }
    }
    
    if($action == 'suggest')
    {
        if(isset($_POST['magv']))
        {
            $magv = $_POST['magv'];            
            $sql = "SELECT * FROM giaovien WHERE MAGIAOVIEN LIKE '". $magv . "%'";
            $result = mysql_query($sql);
            
            if(mysql_num_rows($result) == 0)
                echo 'Giảng viên '. $magv .' không tồn tại';
            else                
                while($row = mysql_fetch_assoc($result))
                {
                    echo $row['MAGIAOVIEN'].' - '.$row['HOTEN'].'<br />';
                }
        }
    }
    if($action == 'load_list')
    {
    ?>
        <center><table>
            <tr style="background: #247CB9;">
                <td style="width: 100px; text-align: center; color: #fff;">Mã GV</td>
                <td style="width: 200px; text-align: center; color: #fff;">Họ tên</td>
                <td style="width: 100px; text-align: center; color: #fff;">Năm sinh</td>
                <td style="width: 50px; text-align: center; color: #fff;">Khoa</td>
                <td style="width: 50px; text-align: center; color: #fff;">Chọn</td>
            </tr>
    <?php
            $sql = mysql_query("SELECT * FROM giaovien");
            while($rows = mysql_fetch_assoc($sql))
            {
    ?>
                 <tr>
<<<<<<< .mine
                 <td style="text-align: center;"><?php echo $rows['MAGIAOVIEN']; ?></td>
                 <td><?php echo $rows['hoten']; ?></td>
                 <td style="text-align: center;"><?php echo $rows['NGAYSINH']; ?></td>
                 <td style="text-align: center;"><?php echo $rows['MAKHOA']; ?></td>
                 <td style="text-align: center;"><input type="checkbox" name="chk_gv[]" id="chk_gv" value="<?php echo $rows['MAGIAOVIEN']; ?>" /></td>
=======
                 <td style="text-align: center;"><?php echo $rows['MAGIAOVIEN']; ?></td>
                 <td><?php echo $rows['HOTEN']; ?></td>
                 <td style="text-align: center;"><?php echo $rows['NGAYSINH']; ?></td>
                 <td style="text-align: center;"><?php echo $rows['MAKHOA']; ?></td>
                 <td style="text-align: center;"><input type="checkbox" name="chk_gv[]" id="chk_gv" value="<?php echo $rows['MAGIAOVIEN']; ?>" /></td>
>>>>>>> .r60
                 </tr>
        <?php } ?>
        </table></center>
    <?php
    }
}

?>